//
// Created by Tony on 2024/5/24.
//

#ifndef PARSER_IF_STMT_H
#define PARSER_IF_STMT_H

#include "../../AstList.h"
#include "BlockStmt.h"

namespace Parser {

class IfStmt final : public AstList {
    string nodeName;

public:
    IfStmt() : AstList({}) { nodeName = __func__; }

    void setCondition(const shared_ptr<Ast>& ast) { children.push_back(ast); }

    shared_ptr<Ast> getCondition() { return children[0]; }

    void setIfBlock(const shared_ptr<BlockStmt>& block) { children.push_back(block); }

    shared_ptr<BlockStmt> getIfBlock() const { return static_pointer_cast<BlockStmt>(children[1]); }

    void setElseBlock(const shared_ptr<Ast>& ast) { children.push_back(ast); }

    shared_ptr<Ast> getElseBlock() {
        if (children.size() > 2) {
            return children[2];
        }
        return nullptr;
    }

    int32_t accept(Compiler::Visitor* visitor) override;
};

} // namespace Parser

#endif // PARSER_IF_STMT_H
